<?php
/**
 * Created by PhpStorm.
 * User: chenshiqi
 * Date: 2018/9/11
 * Time: 17:28
 */

namespace app\common\model;

/**
 * 好友聊天记录模型类
 */
class FriendChatLog extends Common
{
    /**
     * 获取记录总数
     * @param $id
     * @return float|string
     */
    public function countById($id,$user_id){
        return $this->where(['send_uid'=>$id,'receive_uid'=>$user_id])->whereOr(['send_uid'=>$user_id,'receive_uid'=>$id])->count();
    }

    /**
     * 查询范围内的群聊天记录
     * @param $id
     * @param $offset
     * @param int $limit
     * @return array|\PDOStatement|string|\think\Collection
     */
    public function getContentAsc($id,$user_id,$offset,$limit = 10){
        return $this->alias('fcl')
            ->join(['chat_user'=>'u'],'fcl.send_uid = u.id','left')
            ->where(['fcl.send_uid'=>$id,'fcl.receive_uid'=>$user_id])
            ->whereOr(['fcl.send_uid'=>$user_id,'fcl.receive_uid'=>$id])
            ->field('u.id,u.username,u.avatar,fcl.send_content,fcl.send_time')
            ->limit($offset,$limit)
            ->select();
    }
}